package com.migo.controller;

import com.migo.entity.MyTemplateInteractiveRecordEntity;
import com.migo.service.MyTemplateInteractiveRecordService;
import com.migo.utils.PageUtils;
import com.migo.utils.Query;
import com.migo.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * 美映使用，模板素材交互记录(暂时只记录使用和点赞次数)
 * 
 * @author powervision
 * @email wes.wang@powervision.me
 * @date 2021-03-01 11:12:00
 */
@RestController
@RequestMapping("mytemplateinteractiverecord")
public class MyTemplateInteractiveRecordController {
	@Autowired
	private MyTemplateInteractiveRecordService myTemplateInteractiveRecordService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("mytemplateinteractiverecord:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<MyTemplateInteractiveRecordEntity> myTemplateInteractiveRecordList = myTemplateInteractiveRecordService.queryList(query);
		int total = myTemplateInteractiveRecordService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(myTemplateInteractiveRecordList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{materialId}")
	@RequiresPermissions("mytemplateinteractiverecord:info")
	public R info(@PathVariable("materialId") String materialId){
		MyTemplateInteractiveRecordEntity myTemplateInteractiveRecord = myTemplateInteractiveRecordService.queryObject(materialId);
		
		return R.ok().put("myTemplateInteractiveRecord", myTemplateInteractiveRecord);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("mytemplateinteractiverecord:save")
	public R save(@RequestBody MyTemplateInteractiveRecordEntity myTemplateInteractiveRecord){
		myTemplateInteractiveRecordService.save(myTemplateInteractiveRecord);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("mytemplateinteractiverecord:update")
	public R update(@RequestBody MyTemplateInteractiveRecordEntity myTemplateInteractiveRecord){
		myTemplateInteractiveRecordService.update(myTemplateInteractiveRecord);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("mytemplateinteractiverecord:delete")
	public R delete(@RequestBody String[] materialIds){
		myTemplateInteractiveRecordService.deleteBatch(materialIds);
		
		return R.ok();
	}
	
}
